package com.wenhao.JUC;

public class ThreadLocalDemo {
    public static void main(String[] args) {
        ThreadLocal<String> local = new ThreadLocal<>();
        new Thread(() -> {
            local.set("Hello");
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println(local.get());
            // 避免内存泄漏
            local.remove();
        }).start();
        new Thread(() -> {
            local.set("World");
            local.remove();
        }).start();
    }
}
